import pymongo
from bson.objectid import ObjectId

#验证文章富文本内容分割HTML的完整性

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
if "hronet" not in myclient.list_database_names():
    raise Exception("不存在[hronet]数据库")
mydb = myclient["hronet"]
if "hronet_hot" not in mydb.list_collection_names():
    raise Exception("不存在[hronet_hot]集合")
hronetHot_col = mydb["hronet_hot"]
if "hronet_html" not in mydb.list_collection_names():
    raise Exception("不存在[hronet_html]集合")
hronetHTML_col = mydb["hronet_html"]

html = ''
split = list(hronetHTML_col.find({ "hronethotId": ObjectId('60f7940fe124b41a7c67680e')},{'sequence': 1, 'html': 1}))
sorted(split, key=lambda htmlSplit: htmlSplit['sequence'])
for htmlSplit in split:
    html = html + htmlSplit['html']
with open ('xxx.html','wb') as file_object:
    file_object.write(bytes(html, encoding = "utf8"))